package com.timebank.volunteer.controller;

import com.timebank.common.core.web.controller.BaseController;
import com.timebank.common.core.web.page.TableDataInfo;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.common.log.annotation.Log;
import com.timebank.common.log.enums.BusinessType;
import com.timebank.common.security.annotation.InnerAuth;
import com.timebank.common.security.annotation.RequiresLogin;
import com.timebank.volunteer.pojo.vo.VolunteerListVO;
import com.timebank.volunteer.service.VolunteerListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 志愿服务参与名单 表单：volunteer_list
 * @author shiliuyinzhen
 */
@RestController
@RequestMapping("/volunteerList")
@Api(tags = "志愿服务参与名单相关接口")
public class VolunteerListController extends BaseController {

    @Resource
    private VolunteerListService volunteerListService;

    /**
     * 获取志愿服务参与名单列表
     * @param volunteerId
     * @return
     */
    @RequiresLogin
    @GetMapping("/list/{volunteerId}")
    @ApiOperation("获取志愿服务参与名单列表")
    public TableDataInfo getVolunteerListById(@PathVariable("volunteerId") Long volunteerId){
        startPage();
        List<VolunteerListVO> list = volunteerListService.getVolunteerListById(volunteerId);
        return getDataTable(list);
    }

    /**
     * 批量删除志愿服务参与者
     * @param userIds
     * @param map
     * @return
     */
    @RequiresLogin
    @Log(title = "志愿服务参与名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    @ApiOperation("批量删除志愿服务参与者")
    public AjaxResult deleteVolunteerListByUserIds(@PathVariable("userIds")Long[] userIds,@RequestBody Map<String,Integer> map) {
        Long volunteerId = Long.valueOf(map.get("volunteerId"));
        return volunteerListService.deleteVolunteerListByUserIds(userIds,volunteerId);
    }

    /**
     * 根据志愿服务Id获取志愿服务参与名单列表(内部调用)
     * @param volunteerId
     * @return
     */
    @InnerAuth
    @GetMapping("/{volunteerId}")
    @ApiOperation("根据志愿服务Id获取志愿服务参与名单列表(内部调用)")
    public AjaxResult getVolunteerListByVolunteerId(@PathVariable("volunteerId") Long volunteerId){
        List<VolunteerListVO> list = volunteerListService.getVolunteerListById(volunteerId);
        return AjaxResult.success(list);
    }

    /**
     * 获取缺席名单
     * @param volunteerId
     * @return
     */
    @GetMapping("/absent/{volunteerId}")
    @ApiOperation("获取缺席名单")
    public TableDataInfo getAbsentList(@PathVariable("volunteerId") Long volunteerId){
        startPage();
        List<VolunteerListVO>  list = volunteerListService.getAbsentList(volunteerId);
        return getDataTable(list);
    }
}
